package com.xiaochun.jiankangapp.fragment

import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.View
import com.xiaochun.jiankangapp.R
import com.xiaochun.jiankangapp.base.CViewBinding
import com.xiaochun.jiankangapp.databinding.FragmentInputInfoStep1Binding
import com.xiaochun.jiankangapp.extension.onClick

class InputInfoStep1Fragment : InputInfoBaseFragment() {

    @CViewBinding
    lateinit var viewBinding: FragmentInputInfoStep1Binding
    override fun initView(root: View, savedInstanceState: Bundle?) {
        super.initView(root, savedInstanceState)
        viewBinding.man.onClick {
            inputViewModel.gender = 1
            viewBinding.man.setCompoundDrawables(
                null,
                getDrawable(R.mipmap.man2),
                null,
                null
            )
            viewBinding.woman.setCompoundDrawables(
                null,
                getDrawable(R.mipmap.woman1),
                null,
                null
            )
        }
        viewBinding.woman.onClick {
            inputViewModel.gender = 2
            viewBinding.man.setCompoundDrawables(
                null,
                getDrawable(R.mipmap.man1),
                null,
                null
            )
            viewBinding.woman.setCompoundDrawables(
                null,
                getDrawable(R.mipmap.woman2),
                null,
                null
            )
        }
        viewBinding.next.onClick {
            if (inputViewModel.gender == 0) {
                return@onClick
            }
            replaceNext(InputInfoStep2Fragment::class.java)
        }
    }

    private fun getDrawable(id: Int): Drawable {
        return resources.getDrawable(id).apply {
            setBounds(0, 0, intrinsicWidth, intrinsicHeight)
        }
    }
}